import Vue from 'vue';
import { getDATE } from './util'
//import { airport } from './airport/airport.js';
//匹配时间字符串的后4位  "2017-08-09 07:30==>07:30"
Vue.filter("time", function(input) {
	if(input == null || input == undefined || input == "") return "";
	return input.substr(-5);
});
//匹配时间字符串的后月日  "2017-08-09 07:30==>08-09"
Vue.filter("date", function(input) {
	if(input == null || input == undefined || input == "") return "";
	return input.substr(5,5);
});
//匹配时间字符串的的小时分钟 "2017-08-09 07:30:07==>07:30"
Vue.filter("overTime", function(input) {
	if(input == null || input == undefined || input == "") return "";
	return input.substr(11,5);
});
//匹配时间字符串的星期  "2017-08-09 07:30==>星期四"
Vue.filter("week", function(input) {
	if(input == null || input == undefined || input == "") return "";
	var weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
	var myDate = new Date(Date.parse(input.replace(/-/g, "/"))); 
	return weekDay[myDate.getDay()];
});
//机场三字码匹配中文机场名称
Vue.filter("airport", function(input) {
	if(input == null || input == undefined || input == "") return "";
	for(var i=0;i<airport.length;i++){
		if(input==airport[i].airportCode){
			return airport[i].airportCn;
			break;
		}
	}
});
//转换时长   分钟转化为hm
Vue.filter("duration", function(input) {
	if(input == null || input == undefined || input == "") return "";
	input = Number(input);
	let h = parseInt(input/60);
	let m = input-h*60;
	return h+"h"+m+"m";
});
//舱位转化
Vue.filter("cabin", function(input) {
	if(input == null || input == undefined || input == "") return "";
	if(input=="Y") return "经济舱";
	if(input=="F") return "头等舱";
	if(input=="C") return "商务舱";
	else return input;
});
//订单状态转化
Vue.filter("orderStatus", function(input) {
	if(input == null || input == undefined) return "";
	if(input=="0") return "待支付";
	if(input=="1") return "处理中";
	if(input=="2") return "待出票";
	if(input=="4") return "出票完成";
	if(input=="5") return "已取消";
	if(input=="6") return "待确认人数";
	if(input=="9") return "已退款";
	if(input=="10") return "预定失败";
	if(input=="-1") return "押金未支付";
	else return input;
});

//订单状态转化
Vue.filter("otherStatus", function(input) {
	if(input == null || input == undefined || input == "") return "";
	if(input=="WAIT_AUDIT") return "退票待审核";
	if(input=="WAIT_REFUND") return "退票中";
	if(input=="REFUND_SUCCESS") return "退票成功";
	if(input=="REFUND_FAILURE") return "退票失败";
	if(input=="REFUND_OVER") return "已退票";	
	
	if(input=="waiting_for_review") return "改签待审核";	
	if(input=="waiting_for_process") return "改签待处理";	
	if(input=="payed") return "改签已支付";	
	if(input=="gathering_success") return "改签成功";	
	if(input=="review_fail") return "改签审核不通过";	
	if(input=="returned") return "改签退回";	
	if(input=="cancel") return "改签取消";	

	else return "未知";
});

//保险订单状态转化
Vue.filter("insuranceStatus", function(input) {
	if(input == null || input == undefined) return "";
	if(input=="1") return "待支付";
	if(input=="2") return "支付成功";
	if(input=="3") return "支付失败";
	if(input=="4") return "出保成功";
	if(input=="5") return "出保失败";
	if(input=="6") return "退保成功";
	if(input=="7") return "退保失败";
	if(input=="8") return "退保成功未下单";
	if(input=="9") return "已退款";
	else return input;
});

//折扣价显示规则
Vue.filter("discount", function(input) {
	if(input == null || input == undefined || input == "") return "";
	if(input>=100) return '全价';
	return input+"%";
});

//活动类型
Vue.filter("actContent", function(input) {
	if(input == null || input == undefined || input == "") return "";
	if(input==0) return "票面立减"
	if(input==1) return "保险立减"
	else return "未知";
});





